package com.zhugang.week04;

import java.util.HashMap;
import java.util.Map;

/**
 * @program algorithms
 * @description: waysToStep
 * @author: chanzhugang
 * @create: 2022/06/23 22:26
 */
public class WaysToStep2 {

    /**
     * 面试题08.01. 三步问题
     *
     * @param n
     * @return
     */
    Map<Integer, Integer> cache = new HashMap<>();
    int mod = 1000000007;

    public int waysToStep(int n) {
        if (n == 1) {
            return 1;
        }
        if (n == 2) {
            return 2;
        }
        if (n == 3) {
            return 4;
        }
        if (cache.containsKey(n)) {
            return cache.get(n);
        }
        int val = ((waysToStep(n - 1) + waysToStep(n - 2)) % mod + waysToStep(n - 3)) % mod;
        cache.put(n, val);
        return val;

    }
}